using System;
using System.Threading.Tasks;
using ERP.ERPModels.Production.MasterData;
using ERP.HumanResources.Production.MasterData.Dtos;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace ERP.HumanResources.Production.MasterData
{
    /// <summary>
    /// 工序配置服务实现类
    /// </summary>
    public class ProcessConfigurationService : ApplicationService, IProcessConfigurationService
    {
        private readonly IRepository<ProcessConfiguration, int> _processConfigurationRepository;

        public ProcessConfigurationService(IRepository<ProcessConfiguration, int> processConfigurationRepository)
        {
            _processConfigurationRepository = processConfigurationRepository;
        }

        /// <summary>
        /// 获取工序配置
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public async Task<ProcessConfiguration> GetAsync(int id)
        {
            return await _processConfigurationRepository.GetAsync(id);
        }

        /// <summary>
        /// 创建工序配置
        /// </summary>
        /// <param name="input">创建参数</param>
        /// <returns></returns>
        public async Task<ProcessConfiguration> CreateAsync(ProcessConfiguration input)
        {
            input.CreateTime = DateTime.Now;
            return await _processConfigurationRepository.InsertAsync(input);
        }

        /// <summary>
        /// 更新工序配置
        /// </summary>
        /// <param name="id">ID</param>
        /// <param name="input">更新参数</param>
        /// <returns></returns>
        public async Task<ProcessConfiguration> UpdateAsync(int id, ProcessConfiguration input)
        {
            var entity = await _processConfigurationRepository.GetAsync(id);
            
            entity.ProcedureCode = input.ProcedureCode;
            entity.ProcedureName = input.ProcedureName;
            entity.IsNo = input.IsNo;
            entity.Remark = input.Remark;
            entity.UpdateTime = DateTime.Now;
            
            return await _processConfigurationRepository.UpdateAsync(entity);
        }

        /// <summary>
        /// 删除工序配置
        /// </summary>
        /// <param name="id">ID</param>
        /// <returns></returns>
        public async Task DeleteAsync(int id)
        {
            await _processConfigurationRepository.DeleteAsync(id);
        }
    }
} 